#include <iostream>
#define max 400
using namespace std;
int main ()
{int n;
 int flag[max][max]={0};
 int  d[max][max];
 cin>>n;
 for(int i=1;i<=n;i++)
    for(int j=1;j<=i;j++)
        {cin>>d[i][j];
        }
 for(int i=n;i>=1;i--)
   {  
     for(int j=1;j<=n;j++)
       {
        if(flag[i+1][j]>flag[i+1][j+1])   
              flag[i][j]=flag[i+1][j]+d[i][j];
        else  
              flag[i][j]=flag[i+1][j+1]+d[i][j];
              }
              }
 cout<<flag[1][1]<<endl;
 system("pause");
 return 0;
} 
